package com.wutianyi.servlet.upload;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.blobstore.BlobstoreServiceFactory;
import com.google.appengine.api.blobstore.UploadOptions;
import com.wutianyi.utils.NetUtils;

public class UploadActionUrlServlet extends HttpServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 7082608124568972898L;
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
			IOException {
		resp.setContentType("text/plain");
		String redirect = NetUtils.getParameterString(req, "redirect", "0");
		String url = BlobstoreServiceFactory.getBlobstoreService().createUploadUrl(
				"/upload?redirect=" + redirect,
				UploadOptions.Builder.withMaxUploadSizeBytesPerBlob(10000000));
		resp.getWriter().print(url);
	}
	
}
